<?php


namespace app\middleware;
use think\facade\Db;

class Getinfo
{
    public function handle($request, \Closure $next)
    {
        $redis = new \Redis();
        $redis->connect('127.0.0.1', 6379);
        //设置 redis 字符串数据
        $res = $redis->get(app('getsystem')->MacAddInfo());
        if (!$res) {
            session('member',NULL);

            if (request()->post('type') == 'ajax') {
                return json(['status'=>0,'message'=>'请登录后操作']);
            }
 
            return redirect('https://www.zhuhaoduo.cc/index/login/index.html');
        }

        $member = session('member');
        
        if ($member) {
            $request->company_id = '';
            if ($member['default_identity'] == 1) {
                $request->company_id = Db::table('ea_company_management')->where('member_id',$member['id'])->value('company_id');
            }
            $request->default_identity = $member['default_identity'];
        }

        // 把基本的信息存入users对象里
        $request->users = $member;
        $request->userid = $member['id'];

        return $next($request);
    }
}
